package org.cloud.provider.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hjx
 * @title: TopicRabbitConfig
 * @description: TODO
 * @date 2021/10/28
 */
@Configuration
public class TopicRabbitConfig {
    public static final String MESSAGE_TOPIC = "topic_message";
    public static final String NOTICE_TOPIC = "topic_notice";
    public static final String TOPIC_EXCHANGE = "topicExchange";
    //初始化队列
    @Bean
    public Queue firstQueue() {
        return new Queue(TopicRabbitConfig.MESSAGE_TOPIC,true);
    }
    @Bean
    public Queue secondQueue() {
        return new Queue(TopicRabbitConfig.NOTICE_TOPIC,true);
    }
    @Bean
    public TopicExchange exchange(){
        return new TopicExchange(TopicRabbitConfig.TOPIC_EXCHANGE,true,false);
    }
    @Bean
    public Binding bindingExchangeMessage(){
        return BindingBuilder.bind(firstQueue()).to(exchange()).with("topic.message");
    }


    @Bean
    Binding bindingExchangeMessage2() {
        return BindingBuilder.bind(secondQueue()).to(exchange()).with("topic.#");
    }


}
